Repository navigation
Conversation
RecursiveIteratorIterator::callHasChildren(), callGetChildren() and RecursiveFilterIterator::hasChildren() pass their return_value straight to the user method. When that method returns by reference, the reference ends up in the return value of a function that does not return by reference, which trips the assertion in the VM after the call. Unwrap the reference, like CallbackFilterIterator::accept() already does. zend_test's zend_call_method() had the same problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes GH-25404
RecursiveIteratorIterator::callHasChildren(),callGetChildren()andRecursiveFilterIterator::hasChildren()pass theirreturn_valuestraight to the user method. If that method returns by reference, the reference ends up in the return value of a function that is not by-ref, and the assertion after the call in the VM fails.The fix unwraps the reference after the call, the same way
CallbackFilterIterator::accept()and zend_test'szend_call_method_if_exists()already do.zend_return_unwrap_ref()isn't the right fit here: these methods never return by reference, so the reference has to go regardless of how they are called.zend_call_method()in zend_test gets the same fix, since it's the fourth case in the issue.I also went through the other places that pass
return_valueto a user call (array_reduce(),ReflectionProperty::getValue()with a by-ref get hook,CallbackFilterIterator,call_user_func()), and they are fine. One thing I noticed while doing that:PDOStatement::fetchAll(PDO::FETCH_FUNC, ...)with a by-ref function puts the reference into the result array, so writing to the array changes the referenced variable. That is the same on 8.4 and 8.5 and doesn't trip any assertion, so I left it out of this PR.Tested on PHP-8.6 and master (debug + ASan, also with opcache/tracing JIT):
ext/spl/testsandext/zend_test/testsall pass, and both new tests fail without the change.